package com.mapper;

import com.bean.Student;
import org.apache.ibatis.annotations.*;

public interface StudentMapperByAnnotation {

    @Select("select * from t_stu where classid=#{classid}")
    public Student findStuByClassid(int classid);

    @Select("select * from t_stu where stuno=#{stuno}")
    @Results({
            @Result(id = true,column = "stuno",property = "stuno"),
            @Result(column = "stuname",property = "stuname"),
            @Result(column = "grade",property = "grade"),
            @Result(column = "dept",property = "dept"),
            @Result(column = "classid",property = "clazz",
                    one = @One(select = "com.mapper.ClazzMapperByAnnotation.findClazzById")),

    })
    public Student findClazzByStuno(int stuno);

    @Select("select * from t_stu where stuno in (select stuno from t_sc where cid=#{cid})")
    public Student findStuByCourseId(int cid);


    @Select("select * from t_stu where stuno =#{stuno}")
    @Results({
            @Result(id = true,column = "stuno",property = "stuno"),
            @Result(column = "stuname",property = "stuname"),
            @Result(column = "grade",property = "grade"),
            @Result(column = "dept",property = "dept"),
            @Result(column = "stuno",property ="courses",
                    many = @Many(select = "com.mapper.CourseMapperByAnnotation.findCourseByStuno"))
    })
    public Student findCourseForStuByStuno(int stuno);
}
